<cfinclude template="components/settings.cfm">
<cfset hashPut = Hash(Rand(),"MD5")>
<cfset commentPreApprove = "">
<cfset linkCommenterID = "">
<cfset returnMessage = "">
     <cfif IsDefined('doComment')>
    
    	<cfif '#name#' is "" OR '#email#' is "" OR '#theComment#' is "">
         	<cfset returnMessage = "<b>You forgot to enter information into one or more of the required fields.</b>">
        <cfelse>
        	<cfquery name="checkForRegistered" datasource="#fSDS#">
            SELECT * FROM commenters
            WHERE `email` = '#email#'
            </cfquery>
            <cfoutput query="checkForRegistered" maxrows="1" startrow="1">
            	<cfif IsDefined('email')>
					<cfinclude template="components/previousCommenter.cfm">
                <cfelse>
           			<cfinclude template="components/newCommenter.cfm">
				</cfif>
			</cfoutput>
       
         </cfif>
         
     </cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><cfoutput>#fSSN#</cfoutput></title>
</head>

<body>

<cfif IsDefined('URL.postID') OR IsDefined('postID')>

	<cfquery name="getPost" datasource="#fSDS#">
		SELECT * FROM posts
		WHERE `id` = '#postID#'
	</cfquery>

	<cfset postTitle = '#getPost.title#'>

	<cfoutput query="getPost" maxrows="1" startrow="1">
		<h3>#title#</h3>
		<i>Written by #author# at #time# on #date#.</i><br />
		<p>#body#</p>
        <p><i>Permalink to post: <a href="default.cfm?postID=#postID#">http://benfeldman.us/default.cfm?postID=#postID#</a></i></p>
	</cfoutput>

	<cfquery name="getComments" datasource="#fSDS#">
		SELECT * FROM comments
		WHERE `linkID` = '#postID#' AND `commentActivated` = 1
		ORDER BY `commentID` ASC
	</cfquery>

	<cfoutput>
		<p>Below are all the comments for <i>#postTitle#</i>:</p>
        <hr />
	</cfoutput>
    
    <cfoutput query="getComments" startrow="1">
		<h4><cfif #website# is not ""><a href="#website#">#name#</a><cfelse>#name#</cfif></h4>
        <p><i>#commentDate#, #commentTime#</i></p>
        <p>#commentBody#</p>
        <hr />
	</cfoutput>
    
	<p>Would you like to add a comment? Simply fill out the form below and you're all set!</p>

     

     
     <cfoutput>#returnMessage#</cfoutput>
     
     <form action="default.cfm?postID=<cfoutput>#URL.postID#</cfoutput>" method="post">
        <input type="hidden" name="doComment" value="1" />
		Your name: <input type="text" name="name" /><br />
		Your email address: <input type="text" name="email" /><br />
		Your website (optional): <input type="text" name="website" /><br />
			<textarea name="theComment">And of course, your comment.</textarea>
		<input type="submit" value="Submit My Comment" />
	</form>
     
<cfelse> 

	<cfquery name="getPosts" datasource="#fSDS#">
		SELECT * FROM posts
		ORDER BY `id` DESC
	</cfquery>

	<cfoutput query="getPosts" maxrows="10" startrow="1">
    	<h3>#title#</h3>
    	<i>Written by #author# at #time# on #date#</i><br />
    	<p>#body#</p>
	</cfoutput>

</cfif>
<cfinclude template="components/footer.cfm">
</body>
</html>
